/**
 * 
 */
package com.great.meal.search.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author lenovo
 *
 */
@Entity
@Table(name = "t_dishitem")
public class DishItem implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2574921115976293860L;
	private Long itemId;
	private Integer quantity;
	private Dish dish;
	private Double itemPrice;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getItemId() {
		return itemId;
	}
	
	public void setItemId(Long itemId) {
		this.itemId = itemId;
	}
	
	public Integer getQuantity() {
		return quantity;
	}
	
	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}
	
	@Column(name = "dishId")
	public Dish getDish() {
		return dish;
	}
	
	public void setDish(Dish dish) {
		this.dish = dish;
	}
	
	@Transient
	public Double getItemPrice() {
		this.itemPrice = dish.getMoney() * quantity;
		return itemPrice;
	}
	
	public void setItemPrice(Double itemPrice) {
		this.itemPrice = itemPrice;
	}

	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(!(obj instanceof DishItem)) return false;
		
		final DishItem dishItem = (DishItem)obj;
		if(!dishItem.getItemId().equals(getItemId())) return false;
		if(!dishItem.getDish().equals(getDish())) return false;
		if(!dishItem.getQuantity().equals(getQuantity())) return false;
		
		return true;
	}
	@Override
	public int hashCode() {
		int result = itemId != null ? itemId.hashCode() : 0;
		result = result * 31 + (dish != null ? dish.hashCode() : 0);
		result = result * 31 + (quantity != null ? quantity.hashCode() : 0);
		return result;
	}
	
	
}
